﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler
{
    public class GetUserCommandHandler : IRequestHandler<GetUserCommand, APIResult<List<User>>>
    {
        private readonly IBaseRepository<User> userRepos;


        public GetUserCommandHandler(IBaseRepository<User> userRepos)
        {
            this.userRepos = userRepos;
        }

        /// <summary>
        /// 查询用户列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<User>>> Handle(GetUserCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<User>> result = new APIResult<List<User>>();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();

            var list = userRepos.GetAll().Where(x => x.IsDel == false);
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
